package model.pojo;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

import models.util.MySqlDataAccessHelper;



public class AcOrder  implements java.io.Serializable {


	private static final long serialVersionUID = 1L;
	private String orderID;//Ma hoa Don
	private String customerID;// Ma Khach hang
	private Date transactionDate; // Ngay dao Giao Dich
	private int transactionID; // Laoi Gaio Dich
	private int taxID;// ma Thue
	private String employeeID;// Ma Nhan Vien
	private int departmentID;// bo phan
	private String description;
	private Date billingDate;
	private int paymentForm;
	private int paymentMethodID;
	private String customerNameInput;
	private double TaxTotal;
	private double valuationTotal;
	private double total;
	private int status;
	private String recipient;
	private AcTax taxInfo;
		
	
	
	
	public AcTax getTaxInfo(String lang) {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		
		try {
			mysql.open();
			String sql = "select * from ac_tax,ac_tax_lang " +
					"where ac_tax.TaxID=ac_tax_lang.TaxID " +
					"and ac_tax_lang.LangID='"+lang+"' " +
							"and ac_tax.TaxID="+this.taxID;
			ResultSet rs = mysql.executeQuery(sql);
			while (rs.next()) {
				taxInfo = new AcTax();
				taxInfo.setTaxId(rs.getInt("TaxID"));
				taxInfo.setTaxName(rs.getString("TaxName"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			mysql.close();
		}
		return taxInfo;
	}
	
	public void setTaxInfo(AcTax taxInfo) {
		this.taxInfo = taxInfo;
	}
	
	public double getTaxTotal() {
		TaxTotal=0.0;
		Iterator<AcOrderdetail> ls=listorderDetail.iterator();
		while(ls.hasNext()){
			AcOrderdetail a=ls.next();
			TaxTotal+=a.getTaxValue();
		}
		return TaxTotal;
	}
	public void setTaxTotal(double taxTotal) {
		TaxTotal = taxTotal;
	}
	public double getValuationTotal() {
		valuationTotal=0.0;
		Iterator<AcOrderdetail> ls=listorderDetail.iterator();
		while(ls.hasNext()){
			AcOrderdetail a=ls.next();
			valuationTotal+=a.getValuation();
			
		}
		return valuationTotal;
	}
	public void setValuationTotal(double valuationTotal) {
		this.valuationTotal = valuationTotal;
	}
	public String getCustomerNameInput() {
		return customerNameInput;
	}
	public void setCustomerNameInput(String customerNameInput) {
		this.customerNameInput = customerNameInput;
	}

	
	
	
	private ArrayList<AcOrderdetail> listorderDetail;
	public ArrayList<AcOrderdetail> getListorderDetail() {
		return listorderDetail;
	}
	public void setListorderDetail(ArrayList<AcOrderdetail> listorderDetail) {
		this.listorderDetail = listorderDetail;
	}
	public  AcOrder(){
		TaxTotal=0;
		orderID="";
		customerID="KH";
		employeeID="0";
		customerNameInput="";
		billingDate=new Date();
		transactionDate=new Date();
		listorderDetail=new ArrayList<AcOrderdetail>();
		AcOrderdetail.tax=0.00;
		total=0;
		valuationTotal=0;
		recipient="";
		
	}
	
		
	public String getRecipient() {
		return recipient;
	}
	public void setRecipient(String recipient) {
		this.recipient = recipient;
	}
	public String getOrderID() {
		return orderID;
	}
	public void setOrderID(String orderID) {
		this.orderID = orderID;
	}
	public String getCustomerID() {
		return customerID;
	}
	public void setCustomerID(String customerID) {
		this.customerID = customerID;
	}
	public Date getTransactionDate() {
		return transactionDate;
	}
	public void setTransactionDate(Date transactionDate) {
		this.transactionDate = transactionDate;
	}
	public int getTransactionID() {
		return transactionID;
	}
	public void setTransactionID(int transactionID) {
		this.transactionID = transactionID;
	}
	public int getTaxID() {
		return taxID;
	}
	public void setTaxID(int taxID) {
		this.taxID = taxID;
	}
	public String getEmployeeID() {
		return employeeID;
	}
	public void setEmployeeID(String employeeID) {
		this.employeeID = employeeID;
	}
	public int getDepartmentID() {
		return departmentID;
	}
	public void setDepartmentID(int departmentID) {
		this.departmentID = departmentID;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public java.util.Date getBillingDate() {
		return billingDate;
	}
	public void setBillingDate(java.util.Date billingDate) {
		this.billingDate = billingDate;
	}
	public int getPaymentForm() {
		return paymentForm;
	}
	public void setPaymentForm(int paymentForm) {
		this.paymentForm = paymentForm;
	}
	public int getPaymentMethodID() {
		return paymentMethodID;
	}
	public void setPaymentMethodID(int paymentMethodID) {
		this.paymentMethodID = paymentMethodID;
	}
	public double getTotal() {
		total=0.0;
		Iterator<AcOrderdetail> ls=listorderDetail.iterator();
		while(ls.hasNext()){
			AcOrderdetail a=ls.next();
			total+=a.getTotal();
		}
		return total;
	}
	public void setTotal(double total) {
		this.total = total;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public void remove(){
		Iterator<AcOrderdetail> ls=listorderDetail.iterator();
		while(ls.hasNext()){
			AcOrderdetail a=ls.next();
			if(a.isSelected()){
				ls.remove();
			}
		}
	}


}


